<template>
  <div class="enter">
    <div class="head" @click="handleClick"><i class="iconfont icon-head"></i></div>
    <div class="box" :class="{ show: show }">
      <div class="close-btn" @click="show = false">×</div>
      <div class="login">
        <div class="left">
          <div>登录后可享受</div>
          <div>更多贴心服务</div>
        </div>
        <button @click="changeShowLogins()">登录</button>
      </div>
      <ul>
        <li>
          <i class="iconfont icon-locationfill"></i>
          <span>路书</span>
        </li>
        <li>
          <i class="iconfont icon-docment_"></i>
          <span>我的收藏</span>
        </li>
        
        <li>
          <i class="iconfont icon-color"></i>
          <span>主题</span>
        </li>
      </ul>
      <div class="map-type">
        <section @click="handleSelect(index)" v-for="(item, index) in mapTypes" :Key="index">
          <img :src="item.img" />
          <div class="title">{{ item.name }}</div>
          <div class="select" :class="{ active: activedIndex === index }"></div>
        </section>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useCounterStore } from '@/stores/counter.js'
const { changeShowLogins } = useCounterStore()

const show = ref(false) 
const activedIndex = ref(0) 
const mapTypes = [
  { name: '标准', img: '/img/标准.png' },
  { name: '凝黛蓝', img: '/img/凝黛蓝.png' },
  { name: '魅夜黑', img: '/img/魅夜黑.png' },
]

const handleClick = () => {
  show.value = !show.value
}

const emit = defineEmits(['selectmap'])
const handleSelect = (index) => {
  activedIndex.value = index
  emit('selectmap', index)
}
</script>

<style lang="scss" scoped>
.enter {
  position: absolute;
  top: 20px;
  right: 30px;
  .head {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 30px;
    width: 55px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    i {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 50px;
      height: 50px;
      font-size: 40px;
      background: #ddd;
      color: #fff;
      border-radius: 50%;
    }
  }
  .box {
    position: absolute;
    top: 40px;
    right: 0;
    background: #fff;
    border-radius: 10px;
    transition: all 0.3s ease-in-out;
    pointer-events: none;
    opacity: 0;
    &.show {
      pointer-events: auto;
      opacity: 1;
      top: 50px;
    }
    &::before {
      content: '';
      width: 10px;
      height: 10px;
      position: absolute;
      // top: -3px;
      right: 30px;
      // background: rgb(82, 172, 246);
      transform: rotate(45deg);
    }
    .close-btn {
      position: absolute;
      top: 8px;
      right: 12px;
      font-size: 20px;
      color: #888;
      cursor: pointer;
      z-index: 2;
      &:hover {
        color: #f56c6c;
      }
    }
    .login {
      width: 250px;
      display: flex;
      justify-content: space-around;
      background: rgb(82, 172, 246);
      border-radius: 10px 10px 0 0;
      padding: 15px;
      color: #fff;
      font-size: 13px;
      button {
        width: 80px;
        height: 30px;
        color: #fff;
        border: none;
        border: 1px solid #fff;
        border-radius: 5px;
        background: rgb(82, 172, 246);
        outline: none;
        cursor: pointer;
        &:hover {
          background: rgb(69, 183, 246);
        }
      }
    }
    ul {
      list-style: none;
      padding: 15px;
      li {
        height: 40px;
        color: #666;
        font-size: 13px;
        cursor: pointer;
        &:hover {
          color: rgb(82, 172, 246);
        }
      }
    }
    .map-type {
      display: flex;
      justify-content: space-between;
      align-items: center;
      text-align: center;
      padding: 0 20px;
      section {
        position: relative;
        .title {
          font-size: 13px;
          color: #333;
        }
        .select.active {
          position: absolute;
          bottom: 24px;
          left: 0;
          width: 100%;
          height: 30%;
          background: rgba(69, 183, 246, 0.8);
          &::before {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%) rotate(45deg);
            content: '';
            display: block;
            width: 6px;
            height: 8px;
            border: 2px solid #fff;
            border-top: none;
            border-left: none;
          }
        }
      }
    }
  }
}
</style>